convert geojson format to Format class. (#522)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Thu, 26 Mar 2020 14:04:08 +0000 (08:04 -0600)
committerGitHub <noreply@github.com>
Thu, 26 Mar 2020 14:04:08 +0000 (08:04 -0600)
* convert geojson format to Format class.

use gpsbable::File instead of QFile for input.  This results in
better error messages.

use gpsbabel::File for output instead of gbfile.

* detect and log parser errors in geojson reader.

CMakeLists.txt
GPSBabel.pro
Makefile.in
geojson.cc
geojson.h [new file with mode: 0644]
vecs.h

index 2aa1ec612524f3743577380fdf9d322609ab7b3d..a3b851c00ab50f7602048f403c6b88fddee013bc 100644 (file)
@@ -121,6 +121,7 @@ set(HEADERS
   gbser.h
   gbser_private.h
   gbversion.h
+  geojson.h
   ggv_bin.h
   gpx.h
   grtcirc.h
index 051e3c7e7dfac11c5b7340df07186045c81886c3..1a86a582571557cc64f7a9b3579b5de800f1f82a 100644 (file)
@@ -106,6 +106,7 @@ HEADERS =  \
        gbser.h \
        gbser_private.h \
        gbversion.h \
+       geojson.h \
        ggv_bin.h \
        gpx.h \
        grtcirc.h \
index f04c64080d7244ece4aa1f274184aecb65aebd9d..3d6652321e02aff498b5801535b085db48407f9f 100644 (file)
@@ -510,13 +510,13 @@ filter_vecs.o: filter_vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   duplicate.h height.h heightgrid.h interpolate.h nukedata.h polygon.h \
   position.h radius.h reverse_route.h smplrout.h sort.h stackfilter.h \
   swapdata.h trackfilter.h transform.h validate.h gbversion.h vecs.h \
-  format.h ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
-  legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
-  jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
-  jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
-  jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
-  src/core/textstream.h
+  format.h geojson.h src/core/file.h ggv_bin.h gpx.h \
+  src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
+  shape.h shapelib/shapefil.h xcsv.h garmin_fs.h jeeps/gps.h \
+  jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \
+  jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
+  jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
+  jeeps/gpsrqst.h src/core/textstream.h yahoo.h xmlgeneric.h
 formspec.o: formspec.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
   src/core/optional.h
@@ -534,9 +534,9 @@ garmin.o: garmin.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
   jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
   jeeps/gpsrqst.h garmin_tables.h grtcirc.h jeeps/gpsserial.h vecs.h \
-  ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
-  legacyformat.h mynav.h xcsv.h src/core/textstream.h
+  geojson.h src/core/file.h ggv_bin.h gpx.h src/core/xmlstreamwriter.h \
+  src/core/xmltag.h legacyformat.h mynav.h shape.h shapelib/shapefil.h \
+  xcsv.h src/core/textstream.h yahoo.h xmlgeneric.h
 garmin_device_xml.o: garmin_device_xml.cc defs.h config.h zlib/zlib.h \
   zlib/zconf.h formspec.h inifile.h gbfile.h session.h \
   src/core/datetime.h src/core/optional.h garmin_device_xml.h \
@@ -594,7 +594,7 @@ geo.o: geo.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   src/core/file.h
 geojson.o: geojson.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
-  src/core/file.h
+  geojson.h format.h src/core/file.h
 ggv_bin.o: ggv_bin.cc ggv_bin.h defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
   src/core/optional.h format.h
@@ -816,26 +816,26 @@ maggeo.o: maggeo.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
 magproto.o: magproto.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
   src/core/optional.h explorist_ini.h format.h gbser.h magellan.h vecs.h \
-  ggv_bin.h gpx.h src/core/file.h src/core/xmlstreamwriter.h \
-  src/core/xmltag.h shape.h shapelib/shapefil.h yahoo.h xmlgeneric.h \
-  legacyformat.h mynav.h xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h \
-  jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h \
-  jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h \
-  jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h \
-  src/core/textstream.h
+  geojson.h src/core/file.h ggv_bin.h gpx.h src/core/xmlstreamwriter.h \
+  src/core/xmltag.h legacyformat.h mynav.h shape.h shapelib/shapefil.h \
+  xcsv.h garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
+  jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
+  jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
+  jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \
+  yahoo.h xmlgeneric.h
 main.o: main.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   cet_util.h csv_util.h filter.h filter_vecs.h arcdist.h bend.h \
   discard.h duplicate.h height.h heightgrid.h interpolate.h nukedata.h \
   polygon.h position.h radius.h reverse_route.h smplrout.h sort.h \
   stackfilter.h swapdata.h trackfilter.h transform.h validate.h format.h \
-  src/core/file.h src/core/usasciicodec.h vecs.h ggv_bin.h gpx.h \
-  src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
-  shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
-  garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
-  jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
-  jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
-  jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h
+  src/core/file.h src/core/usasciicodec.h vecs.h geojson.h ggv_bin.h \
+  gpx.h src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h \
+  mynav.h shape.h shapelib/shapefil.h xcsv.h garmin_fs.h jeeps/gps.h \
+  jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \
+  jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
+  jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
+  jeeps/gpsrqst.h src/core/textstream.h yahoo.h xmlgeneric.h
 mapasia.o: mapasia.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h
 mapbar_track.o: mapbar_track.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
@@ -966,7 +966,7 @@ skytraq.o: skytraq.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   gbser.h
 smplrout.o: smplrout.cc defs.h config.h zlib/zlib.h zlib/zconf.h \
   formspec.h inifile.h gbfile.h session.h src/core/datetime.h \
-  src/core/optional.h grtcirc.h smplrout.h filter.h
+  src/core/optional.h smplrout.h filter.h grtcirc.h
 sort.o: sort.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
   sort.h filter.h
@@ -1046,14 +1046,14 @@ vcf.o: vcf.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   jeeps/gpsmath.h jeeps/gpsport.h
 vecs.o: vecs.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h \
-  vecs.h format.h ggv_bin.h gpx.h src/core/file.h \
-  src/core/xmlstreamwriter.h src/core/xmltag.h shape.h \
-  shapelib/shapefil.h yahoo.h xmlgeneric.h legacyformat.h mynav.h xcsv.h \
-  garmin_fs.h jeeps/gps.h jeeps/../defs.h jeeps/gpsport.h \
-  jeeps/gpsdevice.h jeeps/gpssend.h jeeps/gpsread.h jeeps/gpsutil.h \
-  jeeps/gpsapp.h jeeps/gpsprot.h jeeps/gpscom.h jeeps/gpsfmt.h \
-  jeeps/gpsmath.h jeeps/gpsmem.h jeeps/gpsrqst.h src/core/textstream.h \
-  gbversion.h src/core/logging.h
+  vecs.h format.h geojson.h src/core/file.h ggv_bin.h gpx.h \
+  src/core/xmlstreamwriter.h src/core/xmltag.h legacyformat.h mynav.h \
+  shape.h shapelib/shapefil.h xcsv.h garmin_fs.h jeeps/gps.h \
+  jeeps/../defs.h jeeps/gpsport.h jeeps/gpsdevice.h jeeps/gpssend.h \
+  jeeps/gpsread.h jeeps/gpsutil.h jeeps/gpsapp.h jeeps/gpsprot.h \
+  jeeps/gpscom.h jeeps/gpsfmt.h jeeps/gpsmath.h jeeps/gpsmem.h \
+  jeeps/gpsrqst.h src/core/textstream.h yahoo.h xmlgeneric.h gbversion.h \
+  src/core/logging.h
 vidaone.o: vidaone.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
   inifile.h gbfile.h session.h src/core/datetime.h src/core/optional.h
 vitosmt.o: vitosmt.cc defs.h config.h zlib/zlib.h zlib/zconf.h formspec.h \
index 9776f5fdf1ca1bcc69a6f3c05723f5a1f5065b98..8f31744f58df526cb317b0011d6d7c08485b3089 100644 (file)
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
  */
-#include "defs.h"
-#include "src/core/file.h"
-#include <QtCore/QJsonArray>
-#include <QtCore/QJsonDocument>
-#include <QtCore/QJsonObject>
 
-static gbfile* ofd;
-static QString input_file_name;
-static const char MYNAME[] = "geojson";
-static char* compact_opt = nullptr;
-static QJsonObject* track_object = nullptr;
-static QJsonArray* track_coords = nullptr;
+#include <QtCore/QByteArray>       // for QByteArray
+#include <QtCore/QIODevice>        // for operator|, QIODevice, QIODevice::ReadOnly, QIODevice::Text
+#include <QtCore/QJsonArray>       // for QJsonArray
+#include <QtCore/QJsonDocument>    // for QJsonDocument, QJsonDocument::Compact, QJsonDocument::Indented, QJsonDocument::JsonFormat
+#include <QtCore/QJsonObject>      // for QJsonObject
+#include <QtCore/QJsonParseError>  // for QJsonParseError
+#include <QtCore/QJsonValue>       // for QJsonValue
+#include <QtCore/QJsonValueRef>    // for QJsonValueRef
 
-static const QString FEATURE_COLLECTION = QStringLiteral("FeatureCollection");
-static const QString FEATURE = QStringLiteral("Feature");
-static const QString POINT = QStringLiteral("Point");
-static const QString MULTIPOINT = QStringLiteral("MultiPoint");
-static const QString LINESTRING = QStringLiteral("LineString");
-static const QString MULTILINESTRING = QStringLiteral("MultiLineString");
-static const QString POLYGON = QStringLiteral("Polygon");
-static const QString MULTIPOLYGON = QStringLiteral("MultiPolygon");
-static const QString TYPE = QStringLiteral("type");
-static const QString FEATURES = QStringLiteral("features");
-static const QString COORDINATES = QStringLiteral("coordinates");
-static const QString GEOMETRY = QStringLiteral("geometry");
-static const QString PROPERTIES = QStringLiteral("properties");
-static const QString NAME = QStringLiteral("name");
-static const QString DESCRIPTION = QStringLiteral("description");
-static const QString URL = QStringLiteral("url");
-static const QString URLNAME = QStringLiteral("urlname");
+#include "defs.h"
+#include "geojson.h"
+#include "src/core/file.h"         // for File
+#include "src/core/logging.h"      // for Fatal
 
-static QVector<arglist_t> geojson_args = {
-  {"compact", &compact_opt, "Compact Output. Default is off.", 
-    nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr } ,
-};
 
-static void
-geojson_rd_init(const QString& fname) {
-       input_file_name = fname;
+void
+GeoJsonFormat::rd_init(const QString& fname) {
+       ifd = new gpsbabel::File(fname);
+       ifd->open(QIODevice::ReadOnly | QIODevice::Text);
 }
 
-static QJsonArray* feature_collection = nullptr;
-
-static void
-geojson_wr_init(const QString& fname) {
+void
+GeoJsonFormat::wr_init(const QString& fname) {
   feature_collection = new QJsonArray;
-  ofd = gbfopen(fname, "w", MYNAME);
+  ofd = new gpsbabel::File(fname);
+  ofd->open(QIODevice::WriteOnly);
 }
 
-static void
-geojson_waypt_pr(const Waypoint* waypoint) {
+void
+GeoJsonFormat::geojson_waypt_pr(const Waypoint* waypoint) const
+{
   QJsonObject geometry;
   geometry[TYPE] = POINT;
   QJsonArray coordinates;
@@ -105,30 +86,32 @@ geojson_waypt_pr(const Waypoint* waypoint) {
   feature_collection->append(feature);
 }
 
-static void
-geojson_rd_deinit() {
-       gbfclose(ofd);
-       ofd = nullptr;
+void
+GeoJsonFormat::rd_deinit() {
+  ifd->close();
+  delete ifd;
+  ifd = nullptr;
 }
 
-static void
-geojson_wr_deinit() {
+void
+GeoJsonFormat::wr_deinit() {
   QJsonObject object;
   object[TYPE] = FEATURE_COLLECTION;
   object[FEATURES]  = *feature_collection;
 
   QJsonDocument save(object);
   QJsonDocument::JsonFormat style = compact_opt ? QJsonDocument::Compact : QJsonDocument::Indented;
-  gbfputs(save.toJson(style),ofd);
+  ofd->write(save.toJson(style));
+  ofd->close();
 
-  gbfclose(ofd);
+  delete ofd;
   ofd = nullptr;
   delete feature_collection;
   feature_collection = nullptr;
 }
 
-static Waypoint* 
-waypoint_from_coordinates(const QJsonArray& coordinates)
+Waypoint* 
+GeoJsonFormat::waypoint_from_coordinates(const QJsonArray& coordinates)
 {
        auto waypoint = new Waypoint();
        waypoint->latitude = coordinates.at(1).toDouble();
@@ -140,8 +123,8 @@ waypoint_from_coordinates(const QJsonArray& coordinates)
        return waypoint;
 }
 
-static void 
-routes_from_polygon_coordinates(const QJsonArray& polygon)
+void 
+GeoJsonFormat::routes_from_polygon_coordinates(const QJsonArray& polygon)
 {
        for (auto && lineStringIterator : polygon)
        {
@@ -156,15 +139,14 @@ routes_from_polygon_coordinates(const QJsonArray& polygon)
        }
 }
 
-static void
-geojson_read() {
-       QFile file;
-       file.setFileName(input_file_name);
-       file.open(QIODevice::ReadOnly | QIODevice::Text);
-       QString file_content = file.readAll();
-       file.close();
+void
+GeoJsonFormat::read() {
+       QString file_content = ifd->readAll();
        QJsonParseError error{};
        QJsonDocument document = QJsonDocument::fromJson(file_content.toUtf8(), &error);
+  if (error.error != QJsonParseError::NoError) {
+    Fatal().nospace() << MYNAME << ": GeoJSON parse error in " << ifd->fileName() << ": " << error.errorString();
+  }
        QJsonObject rootObject = document.object();
 
        if (rootObject[TYPE] != FEATURE_COLLECTION)
@@ -267,7 +249,7 @@ geojson_read() {
 }
 
 
-static void geojson_track_hdr(const route_head* track) {
+void GeoJsonFormat::geojson_track_hdr(const route_head* track) {
   track_object = new QJsonObject();
 
   (*track_object)[TYPE] = FEATURE;
@@ -280,7 +262,8 @@ static void geojson_track_hdr(const route_head* track) {
   (*track_object)[PROPERTIES] = properties;
 }
 
-static void geojson_track_disp(const Waypoint* trackpoint) {
+void GeoJsonFormat::geojson_track_disp(const Waypoint* trackpoint) const
+{
 
   QJsonArray coords;
   coords.append(trackpoint->longitude);
@@ -291,7 +274,7 @@ static void geojson_track_disp(const Waypoint* trackpoint) {
   (*track_coords).append(coords);
 }
 
-static void geojson_track_tlr(const route_head*) {
+void GeoJsonFormat::geojson_track_tlr(const route_head* /*unused*/) {
   QJsonObject geometry;
   geometry[TYPE] = LINESTRING;
   geometry[COORDINATES] = *track_coords;
@@ -303,28 +286,22 @@ static void geojson_track_tlr(const route_head*) {
   track_coords = nullptr;
 }
 
-static void
-geojson_write() {
-  waypt_disp_all(geojson_waypt_pr);
-  track_disp_all(geojson_track_hdr, geojson_track_tlr, geojson_track_disp);
+void
+GeoJsonFormat::write() {
+  auto geojson_waypt_pr_lambda = [this](const Waypoint* waypointp)->void {
+    geojson_waypt_pr(waypointp);
+  };
+  waypt_disp_all(geojson_waypt_pr_lambda);
+
+  auto geojson_track_hdr_lambda = [this](const route_head* rte)->void {
+    geojson_track_hdr(rte);
+  };
+  auto geojson_track_tlr_lambda = [this](const route_head* rte)->void {
+    geojson_track_tlr(rte);
+  };
+  auto geojson_track_disp_lambda = [this](const Waypoint* waypointp)->void {
+    geojson_track_disp(waypointp);
+  };
+  track_disp_all(geojson_track_hdr_lambda, geojson_track_tlr_lambda, geojson_track_disp_lambda);
 }
 
-ff_vecs_t geojson_vecs = {
-  ff_type_file,
-  { 
-       (ff_cap)(ff_cap_read | ff_cap_write) /* waypoints */,
-       (ff_cap)(ff_cap_read | ff_cap_write) /* tracks */,
-       (ff_cap)(ff_cap_read | ff_cap_write) /* routes */, 
-  },
-  geojson_rd_init,
-  geojson_wr_init,
-  geojson_rd_deinit,
-  geojson_wr_deinit,
-  geojson_read,
-  geojson_write,
-  nullptr,
-  &geojson_args,
-  CET_CHARSET_UTF8, 0  /* CET-REVIEW */
-  , NULL_POS_OPS,
-  nullptr  
-};
diff --git a/geojson.h b/geojson.h
new file mode 100644 (file)
index 0000000..e870a6d
--- /dev/null
+++ b/geojson.h
@@ -0,0 +1,108 @@
+/*
+    Copyright (C) 2016 Robert Lipe, robertlipe+source@gpsbabel.org
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+ */
+#ifndef GEOJSON_H_INCLUDED_
+#define GEOJSON_H_INCLUDED_
+
+#include <QtCore/QJsonArray>         // for QJsonArray
+#include <QtCore/QJsonObject>        // for QJsonObject
+#include <QtCore/QStaticStringData>  // for QStaticStringData
+#include <QtCore/QString>            // for QString, QStringLiteral
+#include <QtCore/QVector>            // for QVector
+
+#include "defs.h"
+#include "format.h"                  // for Format
+#include "src/core/file.h"
+
+class GeoJsonFormat : public Format
+{
+public:
+  QVector<arglist_t>* get_args() override
+  {
+    return &geojson_args;
+  }
+
+  ff_type get_type() const override
+  {
+    return ff_type_file;
+  }
+
+  QVector<ff_cap> get_cap() const override
+  {
+    return FF_CAP_RW_ALL;
+  }
+
+  QString get_encode() const override
+  {
+    return CET_CHARSET_UTF8;
+  }
+
+  int get_fixed_encode() const override
+  {
+    return 0;
+  }
+
+  void rd_init(const QString& fname) override;
+  void read() override;
+  void rd_deinit() override;
+  void wr_init(const QString& fname) override;
+  void write() override;
+  void wr_deinit() override;
+
+  void geojson_waypt_pr(const Waypoint* waypoint) const;
+  static Waypoint* waypoint_from_coordinates(const QJsonArray& coordinates);
+  void routes_from_polygon_coordinates(const QJsonArray& polygon);
+  void geojson_track_hdr(const route_head* track);
+  void geojson_track_disp(const Waypoint* trackpoint) const;
+  void geojson_track_tlr(const route_head* unused);
+
+private:
+gpsbabel::File* ifd{nullptr};
+gpsbabel::File* ofd{nullptr};
+const char* MYNAME = "geojson";
+char* compact_opt = nullptr;
+QJsonObject* track_object = nullptr;
+QJsonArray* track_coords = nullptr;
+
+const QString FEATURE_COLLECTION = QStringLiteral("FeatureCollection");
+const QString FEATURE = QStringLiteral("Feature");
+const QString POINT = QStringLiteral("Point");
+const QString MULTIPOINT = QStringLiteral("MultiPoint");
+const QString LINESTRING = QStringLiteral("LineString");
+const QString MULTILINESTRING = QStringLiteral("MultiLineString");
+const QString POLYGON = QStringLiteral("Polygon");
+const QString MULTIPOLYGON = QStringLiteral("MultiPolygon");
+const QString TYPE = QStringLiteral("type");
+const QString FEATURES = QStringLiteral("features");
+const QString COORDINATES = QStringLiteral("coordinates");
+const QString GEOMETRY = QStringLiteral("geometry");
+const QString PROPERTIES = QStringLiteral("properties");
+const QString NAME = QStringLiteral("name");
+const QString DESCRIPTION = QStringLiteral("description");
+const QString URL = QStringLiteral("url");
+const QString URLNAME = QStringLiteral("urlname");
+
+QVector<arglist_t> geojson_args = {
+  {"compact", &compact_opt, "Compact Output. Default is off.", 
+    nullptr, ARGTYPE_BOOL, ARG_NOMINMAX, nullptr } ,
+};
+
+QJsonArray* feature_collection = nullptr;
+
+};
+#endif // GEOJSON_H_INCLUDED_
diff --git a/vecs.h b/vecs.h
index 9e5719fa62ee0e18ec7ee9cb6c227ee7a220867f..c3952440bb5f5c7ded832f9a14a33223e9f0eb86 100644 (file)
--- a/vecs.h
+++ b/vecs.h
@@ -29,6 +29,7 @@
 
 #include "defs.h"
 #include "format.h"
+#include "geojson.h"
 #include "ggv_bin.h"
 #include "gpx.h"
 #include "legacyformat.h"
@@ -172,7 +173,6 @@ extern ff_vecs_t mapbar_track_vecs;
 extern ff_vecs_t f90g_track_vecs;
 extern ff_vecs_t mapfactor_vecs;
 extern ff_vecs_t energympro_vecs;
-extern ff_vecs_t geojson_vecs;
 extern ff_vecs_t globalsat_sport_vecs;
 #endif // MAXIMAL_ENABLED
 
@@ -406,7 +406,7 @@ private:
   LegacyFormat mapfactor_fmt {mapfactor_vecs};
   LegacyFormat energympro_fmt {energympro_vecs};
   MyNavFormat mynav_fmt;
-  LegacyFormat geojson_fmt {geojson_vecs};
+  GeoJsonFormat geojson_fmt;
   GgvBinFormat ggv_bin_fmt;
   LegacyFormat globalsat_sport_fmt {globalsat_sport_vecs};
 #endif // MAXIMAL_ENABLED